package com.cgbl.cg.view

import android.annotation.SuppressLint
import android.content.Context
import android.view.View
import android.widget.AdapterView
import androidx.recyclerview.widget.RecyclerView
import com.cgbl.cg.R
import com.cgbl.cg.adapter.SelectCourseAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.lxj.xpopup.core.AttachPopupView
import com.lxj.xpopup.impl.PartShadowPopupView
import com.robot.base.model.CourseAllTypeBean

@SuppressLint("ViewConstructor")
class SelectCoursePop(context: Context, val select: String, val list: ArrayList<CourseAllTypeBean>) :
    PartShadowPopupView(context) {
    private var confirmClickListener: (id: CourseAllTypeBean) -> Unit = {}
    private lateinit var recyclerView: RecyclerView
    private lateinit var selectCourseAdapter: SelectCourseAdapter
    override fun getImplLayoutId(): Int {
        return R.layout.app_pop_select_course
    }

    override fun initPopupContent() {
        super.initPopupContent()
        recyclerView = findViewById(R.id.recyclerView)
        selectCourseAdapter = SelectCourseAdapter(select)
        recyclerView.adapter = selectCourseAdapter
        selectCourseAdapter.setOnItemClickListener { adapter, view, position ->
            confirmClickListener.invoke(selectCourseAdapter.data[position])
        }
        selectCourseAdapter.setNewInstance(list)
    }


    fun setConfirmClickListener(click: (id: CourseAllTypeBean) -> Unit): SelectCoursePop {
        confirmClickListener = click
        return this
    }
}